home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 November / Macworld (1999-11).dmg / Updaters / WhiteCap 3.0.4 / WhiteCap Source.sit / WhiteCap Source / Common / io / CEgPrefs.cpp < prev    next >
Text File  |  1999-07-13  |  2KB  |  118 lines

  1.  
  2. #include "CEgPrefs.h"
  3.  
  4. #include "Exam.h"
  5. #include "EgOSUtils.h"
  6. #include "CEgFileSpec.h"
  7.  
  8. #include "CEgIOFile.h"
  9.  
  10.  
  11.  
  12.  
  13. bool        CEgPrefs::sPrefsFound    = false;
  14. CEgFileSpec    CEgPrefs::sPrefsSpec;
  15. ArgList        CEgPrefs::sPLFactoryDefaults;
  16. ArgList        CEgPrefs::sPLDefaults;
  17. ArgList        CEgPrefs::sFactoryPrefs;
  18. ArgList        CEgPrefs::sPrefs;
  19.  
  20. #ifdef EG_WIN
  21. #include <windows.h>        // For ::GetCurrentDirectory()
  22. #endif
  23.  
  24. #ifdef EG_MAC
  25. #include <Files.h>
  26. #include <Folders.h>
  27. #endif
  28.  
  29.     
  30. void CEgPrefs::LoadPrefs() {
  31.  
  32.     // Set the factory settings
  33.     sPLFactoryDefaults.SetArgs( "PtSz=11,Font=\"Times\",Ttls=0,IDNm=1,PgBk=0,STit=0,ColL=1,BdMr=0,Cols=1,TopM=54,BotM=36,LftM=36,RgtM=36,Hdr=\"\",Ftr=\"\"" );
  34.     sFactoryPrefs.SetArgs( "" );
  35.  
  36.     #ifdef EG_MAC
  37.       short int    theVRef;
  38.     long        theDirID;
  39.     short        theErr;
  40.     FSSpec        prefSpec;
  41.  
  42.     theErr = ::FindFolder( kOnSystemDisk, kPreferencesFolderType, kCreateFolder, &theVRef, &theDirID );
  43.                     
  44.     if (theErr == noErr) {
  45.         ::FSMakeFSSpec( theVRef, theDirID, "\pExamgen Preferences", &prefSpec );
  46.         sPrefsSpec.Assign( &prefSpec, cPrefType );
  47.     }
  48.     #endif
  49.     
  50.     #ifdef EG_WIN
  51.     UtilStr prefPath;
  52.     char path[ 500 ];
  53.     if ( ::GetCurrentDirectory( 495, path ) ) {
  54.         prefPath.Assign( path );
  55.         prefPath.Append( "\\Examgen Preferences" );
  56.         sPrefsSpec.Assign( prefPath.getCStr(), 0 );
  57.     }
  58.     
  59.     sPLFactoryDefaults.SetArg( 'Font', "Times New Roman" );
  60.     #endif
  61.     
  62.     CEgIFile         prefsFile;        
  63.     UtilStr        str;
  64.     
  65.     prefsFile.open( &sPrefsSpec );
  66.     
  67.     Exam::sFactoryExam.MakeFactory();
  68.     
  69.     if ( prefsFile.noErr() ) {
  70.         Exam::sDefaultExam.ReadFrom( &prefsFile );
  71.         
  72.         // Load PL prefs, having the factor PL prefs be the defaults
  73.         sPLDefaults.SetArgs( sPLFactoryDefaults );
  74.         prefsFile.Readln( str );
  75.         sPLDefaults.SetArgs( str );
  76.         
  77.         // Load program prefs, having the factory PL prefs be the defaults
  78.         sPrefs.SetArgs( sFactoryPrefs );
  79.         prefsFile.Readln( str );
  80.         sPrefs.SetArgs( str );
  81.     }
  82.     
  83.     if ( prefsFile.noErr() && Exam::sDefaultExam.GetAttrib( 0, 'V' ) == 420 ) 
  84.         sPrefsFound = true;
  85.     else {
  86.         prefsFile.close();
  87.         Exam::sDefaultExam.MakeFactory();
  88.         SavePrefs(); 
  89.     }
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96. void CEgPrefs::SavePrefs() {
  97.     CEgIOFile         prefsFile;
  98.     
  99.     prefsFile.open( &sPrefsSpec );
  100.     
  101.     if ( prefsFile.noErr() ) {
  102.         Exam::sDefaultExam.WriteTo( &prefsFile );
  103.         sPLDefaults.ExportTo( &prefsFile );
  104.         prefsFile.Writeln();
  105.         sPrefs.ExportTo( &prefsFile );
  106.         prefsFile.Writeln();
  107.         prefsFile.Writeln();
  108.         prefsFile.Writeln();
  109.     }
  110.     
  111.     if ( ! prefsFile.noErr() )
  112.         EgOSUtils::ShowMsg( "File error writing preferences file." );
  113.  
  114. }
  115.  
  116.  
  117.  
  118.